import {
    SET_EDIT_USER_INFO
} from '../mutation-types';
import api from '../../api';

// import { errFun } from "../../tools.js"
const state = {
    nickname: null,
    id: null,
    age: null,
    sex: null,
    height: null,
    weight: null,
    habit: null,
    phone: null,
    type: null,
    palce: null
    // subscribe:false
}

function setType(type) {
    if (type == 0) {
        type = null
    } else if (type == 1) {
        type = "不限"
    } else if (type == 2) {
        type = "减脂"
    } else if (type == 3) {
        type = "塑型"
    } else if (type == 4) {
        type = "增肌"
    }
    return type;
}

function setPalce(palce) {
    if (palce == 0) {
        palce = null
    } else if (palce == 1) {
        palce = "不限"
    } else if (palce == 2) {
        palce = "背部"
    } else if (palce == 3) {
        palce = "胸部"
    } else if (palce == 4) {
        palce = "臀部"
    }
    return palce;
}
const mutations = {
        [SET_EDIT_USER_INFO](state, data) {
            state.nickname = data.nickname;
            state.age = data.age;
            state.sex = data.sex;
            state.height = data.height + 'cm';
            state.weight = data.weight + 'kg';
            state.habit = data.habit;
            state.type = setType(data.type);
            state.palce = setPalce(data.palce);
            state.id = data.id;
        }
    }
    // ACTION
const actions = {
    GET_EDIT_USER_INFO: ({ commit, dispatch }) => {
        //让loading界面显示
        // dispatch('CHANGE_LOADING_SHOW').then(
        api.getEdit().then(response => {
                commit(SET_EDIT_USER_INFO, response.data);
                // 关闭loading界面
                // dispatch('HIDDEN_LOADING_SHOW')
            })
            // )
    }
}
export default {
    state,
    actions,
    mutations
}